package com.nbjtjc.safe.service.danger;

import cn.hutool.core.util.ObjectUtil;
import com.nbjtjc.safe.mapper.danger.DangerInspectListTypeMapper;
import com.nbjtjc.safe.model.danger.DangerInspectListType;
import com.nbjtjc.safe.util.MyShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther guqianbin
 * @date 2018/9/14 14:09
 **/
@Service
public class DangerInspectListTypeService {

    @Autowired
    private DangerInspectListTypeMapper dangerInspectListTypeMapper;

    public DangerInspectListType add(DangerInspectListType dangerInspectListType){
        dangerInspectListType.setCompanyId(MyShiroUtils.getCompanyId());
        dangerInspectListTypeMapper.insertSelective(dangerInspectListType);
        return dangerInspectListType;
    }

    public boolean delete(DangerInspectListType dangerInspectListType){
        dangerInspectListType=dangerInspectListTypeMapper.selectByPrimaryKey(dangerInspectListType.getId());
        if(ObjectUtil.isNull(dangerInspectListType)){
            return false;
        }
        if(!MyShiroUtils.getCompanyId().equals(dangerInspectListType.getCompanyId())){
            return false;
        }
        dangerInspectListTypeMapper.deleteByPrimaryKey(dangerInspectListType);
        return true;
    }

    public DangerInspectListType update(DangerInspectListType dangerInspectListType){
        String type=dangerInspectListType.getTypeName();
        dangerInspectListType=dangerInspectListTypeMapper.selectByPrimaryKey(dangerInspectListType.getId());
        if(ObjectUtil.isNull(dangerInspectListType)){
            return dangerInspectListType;
        }
        if(!MyShiroUtils.getCompanyId().equals(dangerInspectListType.getCompanyId())){
            return dangerInspectListType;
        }
        dangerInspectListType.setTypeName(type);
        dangerInspectListTypeMapper.updateByPrimaryKeySelective(dangerInspectListType);
        return dangerInspectListType;
    }

    public List<DangerInspectListType> find(DangerInspectListType dangerInspectListType){
        List<DangerInspectListType> dangerInspectListTypes=dangerInspectListTypeMapper.select(dangerInspectListType);
        return dangerInspectListTypes;
    }

}
